/**
 * HTTP 工具类
 */
import axios from 'axios'
export default class Request {
  static async request (method, url, data, loading) {
    var instance = await axios({
      url: url,
      method: 'post',
      baseURL: 'http://127.0.0.1/index.php/index/',
      data: (data ? data : {}),
      // headers: {'content-type': 'x-www-form-urlencoded'},
      timeout: 1000,
      responseType: 'json',
    })
    // console.log(instance)
    if (instance.status === 200 && instance.statusText === 'OK') {
      return instance.data;
    } else {
      console.log('数据异常');
    }
  }
  static get (url, data, loading = true) {
    return this.request('GET', url, data, loading)
  }

  static post (url, data, loading = true) {
    return this.request('POST', url, data, loading)
  }
}
  